package com.his.server.utils.log;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public class DBSqlLog {
	
    public DBSqlLog()
    {
    }
    
    public static void setSqlLogBind(List sqlBindList, String where)
    {
        sqlBindList.add(where);
    }

    public static void setSqlLogBind(List sqlBindList, Date where)
    {
        if(where != null)
            sqlBindList.add(where.toString());
        else
            sqlBindList.add("null");
    }

    public static void setSqlLogBind(List sqlBindList, Integer where)
    {
        if(where != null)
            sqlBindList.add(where.toString());
        else
            sqlBindList.add("null");
    }

    public static void setSqlLogBind(List sqlBindList, Double where)
    {
        if(where != null)
            sqlBindList.add(where.toString());
        else
            sqlBindList.add("null");
    }

    public static void setSqlLogBind(List sqlBindList, BigDecimal where)
    {
        if(where != null)
            sqlBindList.add(where.toString());
        else
            sqlBindList.add("null");
    }

    public static void setSqlLogBind(List sqlBindList, Long where)
    {
        if(where != null)
            sqlBindList.add(where.toString());
        else
            sqlBindList.add("null");
    }

    public static String editSqlLog(String strLog, List bindList)
    {
        if(strLog != null && bindList != null)
        {
            strLog = (new StringBuilder("[SQL] = ")).append(strLog).toString();
            for(int i = 0; i < bindList.size(); i++)
            {
                int index = strLog.indexOf("?");
                if(bindList.get(i) == null)
                    strLog = (new StringBuilder(String.valueOf(strLog.substring(0, index)))).append("null").append(strLog.substring(index + "?".length())).toString();
                else
                    strLog = (new StringBuilder(String.valueOf(strLog.substring(0, index)))).append("'").append(bindList.get(i)).append("'").append(strLog.substring(index + "?".length())).toString();
            }

        }
        return strLog;
    }
}